local skel = fk.CreateSkill {
  name = "lb__lizhou",
}

Fk:loadTranslationTable {
  ["lb__lizhou"] = "黎昼",
  [":lb__lizhou"] = "准备阶段，你可以摸一张牌并视为对所有其他角色使用一张火【杀】，若如此做，结束阶段，所有本回合仅受到过属性伤害的角色将体力值调整至本回合开始时。",

  ["@@lb__lizhou-turn"] = "黎昼",

  ["$lb__lizhou1"] = "新世界，终将到来。",
  ["$lb__lizhou2"] = "为了，下一个明天！",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@lb__lizhou-turn", 1)
    player:drawCards(1, skel.name)
    local tos = Fk:cloneCard("fire__slash"):getAvailableTargets(player, { bypass_distances = true, bypass_times = true })
    room:useVirtualCard("fire__slash", nil, player, tos, skel.name, true)
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local list = player.room:getBanner("Rehearsal_HP") or {}
    return type(list["turn"]) == "table" and player:hasSkill(skel.name) and target == player and data.phase == Player.Finish
        and player:getMark("@@lb__lizhou-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list = (room:getBanner("Rehearsal_HP") or {})["turn"] --用下预演的记录
    if not list or #list == 0 then return end
    local id_hp = {}
    for _, v in ipairs(list) do
      id_hp[v[1]] = v[2]
    end
    for _, to in ipairs(room:getAlivePlayers()) do
      if not to.dead and id_hp[to.id] then --还是防一下戏子之类的
        local hp = id_hp[to.id]
        local reset = false
        room.logic:getEventsOfScope(GameEvent.Damage, 999, function(e)
          local damage = e.data
          if damage.to == to and not damage.prevented then
            if not damage.damageType or damage.damageType == fk.NormalDamage then
              reset = false
              return true
            end
            reset = true
          end
        end, Player.HistoryTurn)
        if reset and hp ~= to.hp then
          if hp > to.hp then
            room:recover {
              who = to,
              num = hp - to.hp,
              skillName = skel.name,
              recoverBy = player,
            }
          else
            room:loseHp(to, to.hp - hp, skel.name)
          end
        end
      end
    end
  end,
})

return skel
